// @ts-ignore
/* eslint-disable */
import { request } from 'umi';
import { ResponsePaginationData, SUCCESS_CODE } from '@/utils/request';
import { MessageItem } from '@/pages/Message/data';

export async function queryNotices(): Promise<ResponsePaginationData<MessageItem>> {
  return await request('/notification/message/list', {
    params: {
      page: 1,
      pageSize: 20,
    },
  });
}

export async function changeReadState(id: number): Promise<boolean> {
  const res = await request('/notification/message/read', {
    method: 'POST',
    params: {
      messageId: id,
    },
  });
  if (res.code === SUCCESS_CODE) {
    return true;
  }
  return false;
}

export async function readAll(ids: number[]): Promise<boolean> {
  const res = await request('/notification/message/readAll', {
    method: 'POST',
    params: {
      messageIds: ids.join(','),
    },
  });
  if (res.code === SUCCESS_CODE) return true;
  return false;
}
